//定义store
import {defineStore} from "pinia";
import {ref} from "vue";
/**
 * 第一个参数： 名字 唯一性
 * 第二个参数： 函数，函数的内部可以定义状态的所有内容
 *返回值： 函数
 */
export const useComputerStore = defineStore('userComputerInfo',()=>{
    //定义状态内容

    //1.响应式变量
    const info = ref({});
    const detail = ref('');
    const userComputerCost = ref(0);
    const clickComputerDetail = ref('');
    const isClose = ref();

    //2.定义一个函数，修改info的值
    const setInfo = (newInfo)=>{
        info.value = newInfo
    }
    const setDetail = (newDetail)=>{
        detail.value = newDetail
    }
    const setInfoUsableTime = (newInfo)=>{
        info.value.usableTime = newInfo
    }
    const setInfoUsableBalance = (newInfo)=>{
        info.value.usableBalance = newInfo
    }
    const setUserComputerCost = (newCost)=>{
        userComputerCost.value = newCost
    }
    const setClickComputerDetail = (newDetail)=>{
        clickComputerDetail.value = newDetail
    }
    const setIsClose = (newClose)=>{
        isClose.value = newClose
    }

    //3.定义函数，移除info的值
    const removeInfo = ()=>{
        info.value = null
    }
    const removeDetail = ()=>{
        detail.value = ''
    }
    const removeUserComputerCost = ()=>{
        userComputerCost.value = 0;
    }
    const removeClickComputerDetail = ()=>{
        clickComputerDetail.value = '';
    }
    const removeIsClose = ()=>{
        isClose.value = null;
    }

    return{
        info,detail,userComputerCost,clickComputerDetail,isClose,
        setInfo,setDetail,setInfoUsableTime,setInfoUsableBalance,setUserComputerCost,setClickComputerDetail,setIsClose,
        removeInfo,removeDetail,removeUserComputerCost,removeClickComputerDetail,removeIsClose
    }
},{
    persist: true //持久化存储
});
